using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarSexAgeDB
    {
        public CarSexAgeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarSexAge carsexage)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarSexAgeInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarSexAgeId", carsexage.ProviderCarSexAgeId);
            _sPara.Add("@ProviderCompanyId", carsexage.ProviderCompanyId);
            _sPara.Add("@Sex", carsexage.Sex);
            _sPara.Add("@FromAge", carsexage.FromAge);
            _sPara.Add("@ToAge", carsexage.ToAge);
            _sPara.Add("@SexAgeRate", carsexage.SexAgeRate);
            _sPara.Add("@RefCEUserId", carsexage.RefCEUserId);
            _sPara.Add("@Status", carsexage.Status);
            _sPara.Add("@FInfo1", carsexage.FInfo1);
            _sPara.Add("@DInfo1", carsexage.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public bool Delete(Int64 ProviderCarSexAgeId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarSexAgeDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarSexAgeId", ProviderCarSexAgeId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }


        public CarSexAgeList GetProviderCarSexAgeList(Int64 ProviderCompanyId)
        {
            CarSexAgeList _carsexagelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarSexAgeSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carsexagelist = new CarSexAgeList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarSexAge _carsexage = new CarSexAge();
                        _carsexage = FillDataRecord(_dt, i);
                        _carsexagelist.Add(_carsexage);
                    }
                }
            }
            return _carsexagelist;
        }


        public CarSexAge GetProviderCarSexAge(Int64 ProviderCompanyId, string Sex)
        {
            CarSexAge _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarSexAgeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@Sex", Sex);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarSexAge();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        public CarSexAge GetProviderCarSexAge(Int64 ProviderCarSexAgeId)
        {
            CarSexAge _vehicleyear = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarSexAgeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarSexAgeId", ProviderCarSexAgeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _vehicleyear = new CarSexAge();
                    _vehicleyear = FillDataRecord(_dt, 0);
                }
            }
            return _vehicleyear;
        }

        private CarSexAge FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarSexAge myCarSexAge = new CarSexAge();
            myCarSexAge.ProviderCarSexAgeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarSexAgeId"].ToString());
            myCarSexAge.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarSexAge.FromAge = Convert.ToInt32(myDataTable.Rows[RowId]["FromAge"].ToString());
            myCarSexAge.ToAge = Convert.ToInt32(myDataTable.Rows[RowId]["ToAge"].ToString());
            myCarSexAge.Sex = myDataTable.Rows[RowId]["Sex"].ToString();
            myCarSexAge.SexAgeRate = Convert.ToSingle(myDataTable.Rows[RowId]["SexAgeRate"].ToString());
            myCarSexAge.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarSexAge.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarSexAge.ModifiedDate = DateTime.Parse(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarSexAge.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarSexAge.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarSexAge.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarSexAge;
        }
        
    }
}